<%@page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.text.*"%>
<%@ page import="java.text.SimpleDateFormat, java.util.Date,java.util.*"%>
<%@ include file="Connections/conDB.jsp" %>
<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", -1); //prevents caching at the proxy server
%>
<% int validaSession = 1; %>
<%@ include file="Connections/session.jsp" %>

<html>
<head>
<title>CIMA v2 - Nuevas Facturas</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="miestilo.css" type="text/css">
</head>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" background="images/fondo.jpg">
<br>
<center>
  <table width="530" border="0" cellspacing="0" cellpadding="0">
    <tr align="center"> 
      <td colspan="8" class="titulos">Nuevas Facturas</td>
    </tr>
    <tr> 
      <td class="titcolumna">&nbsp;&nbsp;&nbsp;</td>
      <td align="center" class="titcolumna">No. Factura</td>
      <td align="center" class="titcolumna">Fecha de Factura</td>
      <td align="center" class="titcolumna">Importe</td>
      <td align="center" class="titcolumna">IVA</td>
      <td align="center" class="titcolumna">Total</td>
      <td align="center" class="titcolumna">Status</td>
    </tr>
	<%
		NumberFormat nf = NumberFormat.getInstance();
		nf.setMaximumIntegerDigits(9); 
		nf.setMaximumFractionDigits(2);
		nf.setMinimumFractionDigits(2); 
		nf.setMinimumIntegerDigits(3);

		String No_Factura = "";
		Date Fecha_Factura = new Date();
		double Importe_porFact = 0.0;
		double IVA_porFact = 0.0;
		double Total_porFact = 0.0;
		double TotalFacturas = 0.0;
		double TotalIVA = 0.0;
		double TotalImporte = 0.0;
		String Tipo_Moneda = "";
		String Estado = "No Conciliado";
		  	Connection ConnRsFactTempo = DriverManager.getConnection(MM_conDB_STRING,MM_conDB_USERNAME,MM_conDB_PASSWORD);
			String queryFactTempo = "";
				    queryFactTempo += "SELECT no_factura,fecha_factura,SUM(importe) AS ImporteXFact, SUM(iva) AS IVAXFact, SUM(total) AS TotalXFact,tipo_moneda ";
					queryFactTempo += "FROM concil_unidad_fact_temp ";
					queryFactTempo += "group by no_factura, fecha_factura,tipo_moneda ";
					queryFactTempo += "order by no_factura, fecha_factura,tipo_moneda ";
			//out.print(queryFactTempo);
			PreparedStatement StatementRsFactTempo = ConnRsFactTempo.prepareStatement(queryFactTempo);
			ResultSet RsqueryFactTempo = StatementRsFactTempo.executeQuery();
			int num = 0;
			while (RsqueryFactTempo!=null && RsqueryFactTempo.next()) {
				num++;
				No_Factura = RsqueryFactTempo.getString("no_factura"); //!=null?RsqueryFactTempo.getString("no_factura"):"&nbsp;";
				Fecha_Factura = RsqueryFactTempo.getDate("fecha_factura"); //!=null?RsqueryFactTempo.getDate("fecha_factura"):"&nbsp;";
				Importe_porFact = RsqueryFactTempo.getDouble("ImporteXFact"); 
				IVA_porFact = RsqueryFactTempo.getDouble("IVAXFact");
				Total_porFact = RsqueryFactTempo.getDouble("TotalXFact");
				//out.println("<br>  Importe - " +Importe_porFact +" - IVA - "+IVA_porFact+" - Total -" +Total_porFact+"<br>");
				Tipo_Moneda = RsqueryFactTempo.getString("tipo_moneda");
				
	%>
	    <tr bgcolor="#DCDFC8"> 
	      <td align="center" class="textcolumna" ><%=num%></td>
		  <td align="center" class="textcolumna" ><%=No_Factura%></td>
			<%
				SimpleDateFormat dateformat = new SimpleDateFormat("dd-MM-yyyy",Locale.US);
			%>
	      <td align="center" class="textcolumna" ><%=dateformat.format(Fecha_Factura)%></td>
    	  <td align="right" class="textcolumna" >$<%=nf.format(Importe_porFact)%></td>
	   	  <td align="right" class="textcolumna" >$<%=nf.format(IVA_porFact)%></td>
	      <td align="right" class="textcolumna" >$<%=nf.format(Total_porFact)%></td>
    	  <td align="center" class="textcolumna" ><%=Estado%></td>
	  </tr>
	  <%
	  TotalImporte = TotalImporte + Importe_porFact;
	  TotalIVA = TotalIVA + IVA_porFact;
	  TotalFacturas = TotalFacturas + Total_porFact;
	  }
	  %>
	  <tr>
	  <td align="right" class="textcolumna">&nbsp;</td>
	  <td align="right" class="textcolumna">&nbsp;</td>
	  <td align="right" class="textcolumna"> Total de las Facturas&nbsp;</td>
	  <td align="right" class="resultado">$&nbsp;<%=nf.format(TotalImporte)%></td>
	  <td align="right" class="resultado">$&nbsp;<%=nf.format(TotalIVA)%></td>
      <td align="right" class="resultado">$&nbsp;<%=nf.format(TotalFacturas)%></td>
	  <td align="right" class="textcolumna">&nbsp;</td>
	  </tr>
  </table>
 <br>
  <table width="300" border="0" cellpadding="0" cellspacing="0">
    <tr> 
      <td align="center"> 
        <!--<input type="button" name="Button" value="Subir Facturas" class="boton" onClick="javascript:location.replace('concilTFM_subirfacturas.jsp');">-->
        <a href="javascript:location.replace('concilTFM_subirfacturas.jsp');"><img src="images/bSubirFact.gif" width="117" height="18" border="0"></a>
        <!--<input type="button" name="Button2" value="Cancelar Facturas" class="boton" onClick="javascript:location.replace('concilTFM_nosubirfacturas.jsp');">-->&nbsp;
        <a href="javascript:location.replace('concilTFM_listaFact.jsp');"><img src="images/bCancelarFact.gif" width="131" height="18" border="0"></a></td>
    </tr>
  </table>
</center>
</body>
<HEAD>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</HEAD>
</html>
